import * as constants from './constants';
import { fromJS } from 'immutable';
import { Conf } from '../../../utils';

const defaultState=fromJS({
    list:[],
    loading:true,
    total:0,
    emptyText:'暂无数据',
    page:1,
    pageSize:Conf.page_Conf.pageSize,
    formData:{
        arr:['name',"img",'start_time','end_time','url','description']
        ,name:{type:'input',title:'广告标题',name:'name',autoFocus:true,placeholder:"请输入广告标题",rules:[{
            required: true,
            whitespace: true,
            message: '广告标题不能为空'
        }]}
        ,img:{type:'input.hidden',title:'图片',name:'img'}
        ,start_time:{type:'input.time',title:'上线时间',name:'start_time'}
        ,end_time:{type:'input.time',title:'下线时间',name:'end_time'}
        ,description:{type:'text',title:'图片提示',rows:4,name:'description'}
        ,url:{type:'input',title:'链接地址',name:'url'}
    }
});
export default (state=defaultState,action)=>{
    switch (action.type) {
        case constants.LIST:
            return state.merge({
                list : fromJS(action.list),
                total : action.total
            })
        case constants.LOADING:
            return state.merge({
                loading : action.loading
            })
        case constants.NOAUTH:
            return state.merge({
                emptyText : action.emptyText
            })
            
        case constants.PAGESIZE:
            return state.merge({
                pageSize : action.pageSize
            })
        case constants.PAGE:
            return state.merge({
                page : action.page
            })
        default:
            break;
    }
    return state;
}